﻿using Mimas.Core.Current;
using Mimas.Framework.Shared.Data.DataTransferObjects;
using System;
using System.Linq;

namespace Mimas.Framework.Server.DomainObjects.Mapping
{
    public static class CountryLangMapping
    {
        public static CountryLang Map(CountryLangDTO data)
        {
            CountryLang newItem = new CountryLang();

            newItem.Id = data.Id;
            newItem.LanguageId = data.LanguageId;
            newItem.CountryId = data.CountryId;
            newItem.Name = Culture.ToTitleCase(data.Name);

            if (data.Id == 0)
            {
                newItem.CreatedBy = UserInfo.CurrentUser.UserId;
                newItem.CreatedOn = DateTime.Now;
            }
            else
            {
                newItem.ModifiedBy = UserInfo.CurrentUser.UserId;
                newItem.ModifiedOn = DateTime.Now;
            }

            return newItem;
        }

        public static CountryLangDTO Map(CountryLang data)
        {
            CountryLangDTO newItem = new CountryLangDTO();

            newItem.Id = data.Id;
            newItem.LanguageId = data.LanguageId;
            newItem.CountryId = data.CountryId;
            newItem.Name = Culture.ToTitleCase(data.Name);

            return newItem;
        }

        public static CountryLang[] Map(CountryLangDTO[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }

        public static CountryLangDTO[] Map(CountryLang[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }
    }
}
